
<template>
  <router-view></router-view>
  <van-tabbar v-model="active" @change="onChange">
    <van-tabbar-item icon="home-o" to="/home" >首页</van-tabbar-item>
    <van-tabbar-item icon="cart-o" to="/cart">购物车</van-tabbar-item>
    <van-tabbar-item icon="user-o" to="/my">我的</van-tabbar-item>
    
  </van-tabbar>
</template>

<script>
import { ref,getCurrentInstance } from 'vue';
//import { Toast } from 'vant';
import router from './router';
export default{
  setup(){
    const {proxy} = getCurrentInstance()
    const active = ref(0);
    const onChange = (index) => {
      console.log('index',index);
      //
      if (index == 1) {
        if (localStorage.getItem('isLogin')) {
          router.push('/cart')
        }else{
          //Toast('请先登录')
          proxy.$toast('请先登录')
          setTimeout(() => {
            router.push('/login')
          }, 1000);
        }
      }
      if (index == 2) {
        if (localStorage.getItem('isLogin')) {
          router.push('/my')
        }else{
          //Toast('请先登录')
          proxy.$toast('请先登录')
          setTimeout(() => {
            router.push('/login')
          }, 1000);
        }
      }
    };
    return {
      active,
      onChange
    }
  }
}
</script>

<style scoped></style>
 